import {
  Controller,
  Get,
  Inject,
  Res,
  Headers,
  UnauthorizedException,
  UseGuards,
  Post,
  UseInterceptors,
  UploadedFiles,
  Body,
  Query,
  Header,
  StreamableFile,
} from '@nestjs/common';
import { AppService } from './app.service';
import { JwtService } from '@nestjs/jwt';
import { ConfigService } from '@nestjs/config';
import { Response } from 'express';
import * as fs from 'fs';
import * as path from 'path';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Inject(JwtService)
  private jwtService: JwtService;

  @Inject(ConfigService)
  private configService: ConfigService;

  @Get()
  getHello(): string {
    // console.log(this.configService.get('alioss'));
    return this.appService.getHello();
  }

  @Get('download')
  download() {
    const stream = fs.createReadStream(
      path.join(process.cwd(), 'package.json'),
    );
    return new StreamableFile(stream, {
      type: 'text/plain',
      disposition: `attachment; filename="package.json"`,
    });
  }
}
